#ifndef __SVR_H__
#define __SVR_H__

#include <soar.h>

__BEGIN_DECLS

extern char *SERVER_NAME;

struct cnfg_info
{/*{{{*/
    unsigned int ipckey;
    struct
    {
        char location[LONG_FILE_NM_SIZE+1];
    } _errlog_;
    struct
    {
        char name[NAME_SIZE+1];
        char user[NAME_SIZE+1];
        char database[NAME_SIZE+1];
        char host[NAME_SIZE+1];
        MYSQLC *db;
    } _db_;
    int start;
    char sn_passwd_addr[LONG_FILE_NM_SIZE+1];
};/*}}}*/
extern struct cnfg_info cnfg_info;

struct stat_info
{/*{{{*/
    struct
    {
        pthread_mutex_t lock;
        struct _worker_info
        {
            int client_num;
        } *worker;
    } _worker_;

    struct
    {
        pthread_mutex_t lock;
        struct _svc_info
        {
            char *name;
            unsigned int loop;
            unsigned int count;
        } *svc;
    } _svc_;
};/*}}}*/
extern struct stat_info stat_info;

enum thrd_state { THRD_RUNNING, THRD_SHUTDOWN };
struct operate_info
{/*{{{*/
    struct
    {
        pthread_mutex_t lock;
        unsigned int quit;
        enum thrd_state state;
    }
    _listener_;

    struct
    {
        pthread_mutex_t lock;
        unsigned int quit;
        enum thrd_state *state;
    }
    _worker_;
};/*}}}*/
extern struct operate_info operate_info;

/*----- 服务 -----*/
typedef int (*P_SVC_FUNC)(MYSQLC, char *, char *);
#define SVC_FUNC(svc)   \
int SVC_FUNC_##svc(MYSQLC db, char *request, char *respond)
struct svc_map
{
    char *name;
    P_SVC_FUNC pfunc;
};
extern struct svc_map SVC_MAP[];
extern unsigned int SVC_MAP_SIZE;

__END_DECLS

#endif
